package com.icss.train_sys_back.mapper.train_manage;

import com.icss.train_sys_back.entity.train_manage.StationEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author wk
 * @desc
 * @date 2025/9/23 14:17
 */
@Mapper
public interface StationMapper {
    @Select({"<script>",
            "SELECT * FROM t_station s"+
            " LEFT JOIN t_railwaybureau rb ON s.railway_bureau_id = rb.bureau_id"+
            "<where>"+
            " <if test='stationName != null'> s.station_name LIKE CONCAT('%', #{stationName}, '%')</if>"+
            " <if test='province != null'> and s.province like CONCAT('%',#{province},'%')</if>" +
            "</where>"+
            " </script>"})
    @Results({
            @Result(property = "railwayBureauEntity.bureauId", column = "bureau_id"),
            @Result(property = "railwayBureauEntity.bureauName", column = "bureau_name"),
            @Result(property = "railwayBureauEntity.bureauCode", column = "bureau_code")

    })
    List<StationEntity> findStationList(String stationName, String province);
    @Insert("insert into t_station values(null,#{stationName},#{city},#{province},#{railwayBureauId},#{address},#{contactPhone},now(),now())")
    boolean save(StationEntity stationEntity);
    @Update("update t_station set station_name=#{stationName},city=#{city},province=#{province},railway_bureau_id=#{railwayBureauId},contact_phone=#{contactPhone},address=#{address},update_time=now() where station_id=#{stationId} ")
    boolean update(StationEntity stationEntity);
    @Delete("delete from t_station where station_id=#{id}")
    boolean delete(Integer id);

    //根据id获取站点
    @Select("select * from t_station where station_id = #{stationId}")
    StationEntity getStationBySid(Integer stationId);
}
